package com.woniu.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.commons.exception.VenueRuntimeException;
import com.woniu.dao.YCoachEnterVenueMapper;
import com.woniu.model.form.AddCoachEnterVanueForm;
import com.woniu.model.model.YCoachEnterVenue;
import com.woniu.service.YCoachEnterVenueService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author EdisonLiu
 * @since 2024年05月23日
 */
@Service
public class YCoachEnterVenueServiceImpl extends ServiceImpl<YCoachEnterVenueMapper, YCoachEnterVenue> implements YCoachEnterVenueService {

    @Resource
    private YCoachEnterVenueMapper coachEnterVenueMapper;
    @Override
    public Integer addCoachEnterVanue(AddCoachEnterVanueForm form) {
        List<YCoachEnterVenue> list = coachEnterVenueMapper.selectList(new QueryWrapper<YCoachEnterVenue>().eq("coach_id", form.getCoachId()).eq("venue_id", form.getVenueId()));
        if (list.size()!=0){
            throw new VenueRuntimeException(3014,"该场馆，教练关系已绑定");
        }
        YCoachEnterVenue coachEnterVenue = BeanUtil.toBean(form, YCoachEnterVenue.class);
        Integer i = coachEnterVenueMapper.insert(coachEnterVenue);

        return i;
    }
}
